package com.example.android.databases

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.example.android.daos.MessageViewDao
import com.example.android.models.MessageView
import com.example.android.utils.RoomTypeConverter

/**
 * @ClassName MessageViewDatabase
 * @Author Ryan Kamanri
 * @Date 2022/6/12
 * @Description
 **/
@Database(version = 1, entities = [MessageView::class])
@TypeConverters(RoomTypeConverter::class)
abstract class MessageViewDatabase : RoomDatabase() {
    abstract fun messageViewDao(): MessageViewDao

    companion object {
        private var instance: MessageViewDatabase? = null

        @Synchronized
        fun getDataBase(context: Context): MessageViewDatabase {
            instance?.let { it }

            return Room.databaseBuilder(
                context.applicationContext,
                MessageViewDatabase::class.java,
                "messageviews")
                .build()
                .apply {
                    instance = this
                }

        }
    }
}